package com.devunion.bogdan.view.project.actions;

import com.devunion.bogdan.view.project.AbstractEntryNode;
import com.devunion.bogdan.view.LibrarianEditor;
import com.devunion.bogdan.model.project.Paper;

import javax.swing.*;
import java.awt.event.ActionEvent;

/**
 * @author Viktar Liaskovich
 */
public abstract class AbstractProjectAction extends AbstractAction {

    protected AbstractProjectAction() {
    }

    protected AbstractProjectAction(String name) {
        super(name);
    }

    protected AbstractProjectAction(String name, Icon icon) {
        super(name, icon);
    }

    protected Paper getPaper(ActionEvent e) {
        final JTree projectTree = LibrarianEditor.getInstance().getSelectedWorkspace().getProjectTreeBrowser().getProjectTree();

        return (Paper) ((AbstractEntryNode) projectTree.getLastSelectedPathComponent()).getUserObject();
    }

    /**
     * Must enable or disable Menu item in dependenco of context.
     * @param e project entry node
     * @return <code>true</code> if current acction applicable to the node and <code>false</code>
     * in other way
     */
    public abstract boolean isApplicable(Paper e);

}
